﻿using log4net.Core;
using log4net.Layout.Pattern;

namespace HY.Common
{
    public class LogConverter : PatternLayoutConverter
    {
        protected override void Convert(System.IO.TextWriter writer, LoggingEvent loggingEvent)
        {
            LogInfo logInfo = loggingEvent.MessageObject as LogInfo;
            if (logInfo == null)
            {
                writer.Write("");
            }
            else
            {
                switch (this.Option.ToLower())
                {
                    case "userid":
                        writer.Write(logInfo.UserID);
                        break;
                    case "logtype":
                        writer.Write((int)logInfo.LogType);
                        break;
                    case "logmessage":
                        writer.Write(logInfo.LogMessage);
                        break;
                    default:
                        writer.Write("");
                        break;
                }
            }
        }
    }
}
